<!--
 * @Author: White
 * @description: 登录模块
 * @LastEditTime: 2021-08-25 09:40:23
-->

<template>
    <div class="login">
        <div class="login-img">
            <i v-if="!user.profile" class="el-icon-s-custom"></i>
            <img v-if="user.profile" :src="user.profile.avatarUrl" alt="">
        </div>
        <div class="login-status" @click="register" v-if="!user.profile">
            <div class="no" :style="{ 'color': theme.text }">
                <p class="login-name">未登录</p>
                <i class="el-icon-caret-right"></i>
            </div>
        </div>
        <div class="login-status">
            <div class="yes" v-if="user.profile" :style="{ 'color': theme.text }">
                {{user.profile.nickname}}
                <el-popover
                    placement="right"
                    :width="320"
                    trigger="click">
                    <div class="popover">
                        <div class="popover-item">
                            <div class="popover-number">{{user.profile.eventCount}}</div>
                            <div class="popover-title">动态</div>
                        </div>
                        <div class="popover-item">
                            <div class="popover-number">{{user.profile.followeds}}</div>
                            <div class="popover-title">关注</div>
                        </div>
                        <div class="popover-item">
                            <div class="popover-number">{{user.profile.follows}}</div>
                            <div class="popover-title">粉丝</div>
                        </div>
                    </div>
                    <div class="center">
                        <div>会员中心</div>
                        <div>登记</div>
                        <div>商场</div>
                    </div>
                    <div class="outlogin">
                        <div @click="loginout">退出登录</div>
                    </div>
                    <template #reference>
                        <i class="el-icon-caret-right" @click="detail"></i>
                    </template>
                </el-popover>
            </div>
        </div>
    </div>
</template>

<script>
import { ref, watch, computed } from 'vue'
import { useStore } from 'vuex'
export default {
    emits: ['register'],
    setup(props, { emit }) {
        let user = ref('')
        const store = useStore()
        const theme = computed(() => store.state.theme)
        user.value = store.getters.userInfo
        watch(() => store.state.userInfo, (val, old) => {
            user.value = val
        })
        // 定义派发事件 -- 未登录
        const register = () => {
            emit("register", true);
        }
        // 退出登录
        const loginout = () => {
            store.commit('loginout', [])
        }
        return {
            theme,
            register,
            loginout,
            user
        }
    }
}
</script>

<style lang="scss" scoped>
    .login {
        width: 100%;
        height: 40px;
        display: flex;
        align-items: center;
        margin: 10px 0px;
        cursor: pointer;
        z-index: 999;
        .login-img {
            width: 40px;
            height: 40px;
            background-color: #e0e0e0;
            text-align: center;
            border-radius: 50%;
            margin: 0px 10px;
            i {
                line-height: 40px;
                width: 40px;
                height: 40px;
                background-color: #e0e0e0;
                color: #fff;
                border-radius: 50%;
            }
            img {
                width: 40px;
                height: 40px;
                border-radius: 50%;
            }
        }
        .login-status {
            display: flex;
            .no {
                display: flex;
                .login-name {
                    font-size: 14px;
                    margin-right: 8px;
                }
                i {
                    color: gray;
                }
            }
            .yes {
                display: flex;
                align-items: center;
                font-size: 14px;
                margin-right: 8px;
                position: relative;
                i {
                    color: gray;
                }
            }
        }
    }
    .popover {
        display: flex;
        justify-content: center;
        padding: 24px 0;
        border-bottom: 1px solid #d9d9d9;
        .popover-item:last-child {
            border-right: none;
        }
        .popover-item {
            width: 33.33%;
            text-align: center;
            border-right: 1px solid #ededed;
            cursor: pointer;
            .popover-number {
                color: #333;
                font-size: 27px;
                font-weight: 700;
            }
            .popover-text {
                font-size: 13px;
                color: #666;
                text-align: center;
                cursor: pointer;
            }
        }
    }
    .center {
        overflow: hidden;
        padding: 6px 0;
        border-bottom: 1px solid #d9d9d9;
        div {
            width: 100%;
            height: 32px;
            line-height: 32px;
            padding-left: 24px;
        }
        div:hover {
           background: #f2f2f2;
        }
    }
    .outlogin {
        div {
            height: 32px;
            line-height: 42px;
            padding-left: 24px;
        }
    }
</style>